<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <link rel="stylesheet" href="/${BasePath}/static/mobile/css/base.css" />
    <link rel="stylesheet" href="/${BasePath}/static/mobile/css/style.css" />
    <link rel="stylesheet" href="/${BasePath}/static/mobile/css/swiper.min.css" />
    <link rel="stylesheet" href="/${BasePath}/static/mobile/css/ydui.css" />
    <link rel="stylesheet" href="/${BasePath}/static/mobile/css/validate.css" />
    <title>半岛云</title>  
</head>
<body>
    <input type="hidden" id="active" value="grzx">
	<div class="wrap">
		<!--标题栏-->
		<div class="fixed_top">
			<div class="top-l"><a href="javascript:window.history.back()"><i class="icons">&#xe626;</i></a></div>
			<h2>新建地址</h1>
		</div>
		<div class="container">	
			<form class="m-cell" id="addressForm">
				<input type="hidden" name="provance" id="provance" value="">
				<input type="hidden" name="city" id="city" value="">
				<input type="hidden" name="area" id="area" value="">		
				<div class="cell-item">
				    <div class="cell-left width100px">收货人姓名：</div>
				    <div class="cell-right"><input type="text" name="name" class="cell-input"  placeholder="收货人姓名" autocomplete="off" data-required="true" data-descriptions="username"/></div>
				</div>
				<div class="cell-item">
				    <div class="cell-left width100px">手机号：</div>
				    <div class="cell-right"><input type="text" name="phone" class="cell-input" placeholder="请输入手机号" autocomplete="off" data-validate="phone" data-describedby="phone-description" /></div>
				</div>			    
				<div class="cell-item">
				    <div class="cell-left width100px">收货地址：</div>
				    <div class="cell-right cell-arrow"><input type="text" id="J_Address" readonly class="cell-input"  placeholder="请选择收货地址" autocomplete="off" data-required="true" data-descriptions="J_Address"/></div>
				</div>
				<div class="cell-item">
				    <div class="cell-left width100px">详细地址：</div>
				    <div class="cell-right"><input type="text" name="address" class="cell-input"  placeholder="请输入详细地址" autocomplete="off" data-required="true" data-descriptions="address"/></div>
				</div>			
			</form>
			<a class="tj" id="tj">提 交</a>
		
		<#include "/common/foot.html">
	</div>
</body>
<script type="text/javascript" src="/${BasePath}/static/mobile/js/ydui.flexible.js"></script>
<script type="text/javascript" src="/${BasePath}/static/mobile/js/ydui.js"></script>
<script type="text/javascript" src="/${BasePath}/static/mobile/js/ydui.citys.js"></script>
<script type="text/javascript" src="/${BasePath}/static/mobile/js/jquery-mvalidate.js"></script>
<script type="text/javascript">
/**
 * 默认调用
 */
!function () {
    var $target = $('#J_Address');

    $target.citySelect();

    $target.on('click', function (event) {
        event.stopPropagation();
        $target.citySelect('open');
    });

    $target.on('done.ydui.cityselect', function (ret) {
        $(this).val(ret.provance + ' ' + ret.city + ' ' + ret.area);
        $("#provance").val(ret.provance);
        $("#city").val(ret.city);
        $("#area").val(ret.area);
    });
}();

    $(function(){    	
        $.mvalidateExtend({
            phone:{
                required : true,   
                pattern : /^1[34578]\d{9}$/,
                each:function(){  
                },
                descriptions:{
                    required : '<div class="field-invalidmsg">请输入手机号码</div>',
                    pattern : '<div class="field-invalidmsg">您输入的手机号码格式不正确</div>',
                    valid : '<div class="field-validmsg">正确</div>'
                }
            }
        });
       
        $("#addressForm").mvalidate({
            type:1,
            onKeyup:true,
            sendForm:false,
            onKeyup:true,
            firstInvalidFocus:true,
            eachField:function(){

            },
            valid:function(){
                $.ajax({
                    cache: true,
                    type: "POST",
                    url: "/${BasePath}/main/saveAddress",
                    data: $('#addressForm').serialize(),
                    async: false,
                    error: function(request) {
                    	YDUI.dialog.alert('提交失败，请稍后再试！');
                    },
                    success: function(data) {
                        if(data.code = "1") {
    	                	YDUI.dialog.toast(data.msg, 'success', 2000, function () {
    	                		window.location.href="/${BasePath}/main/address";
    	                	}); 
                        } else {
                        	YDUI.dialog.alert(data.msg);
                        }
                    }
                });                
            },
            invalid:function(){
               
            },
            eachValidField:function(){
              
            },
            eachInvalidField:function(){
               
              
            },
            descriptions:{
                username:{
                    required : '<div class="field-invalidmsg">请输入姓名</div>',
                    valid : '<div class="field-validmsg">验证通过</div>'
                }, 
                J_Address:{
                    required : '<div class="field-invalidmsg">请选择收货地址</div>',
                    valid : '<div class="field-validmsg">验证通过</div>'
                },      
                address:{
                    required : '<div class="field-invalidmsg">请输入详细地址</div>',
                    valid : '<div class="field-validmsg">验证通过</div>'
                }
            }
        });
        
        $("#tj").click(function(){
        	 $('#addressForm').submit();
        	});
 
	})


</script>

</html>